package com.dalu.app.ui

import android.app.Activity
import android.os.Bundle
import android.support.v4.app.FragmentTransaction
import android.support.v7.app.AppCompatActivity
import com.dalu.app.utils.StatusBarUtil
import java.util.ArrayList

/**
 * Created by zgh on 2017/12/28.
 * Mail zhangguanghui163@163.com
 */
abstract class BaseActivity : AppCompatActivity() {
    var mArrayList = ArrayList<Activity>()



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutResouse())
//        StatusBarUtil.setTranslucentForImageViewInFragment(this,0, null)
        mArrayList.add(this)
        initView()


    }

    abstract fun initView()

    abstract fun getLayoutResouse(): Int




    /**
     * 替换 Fragment
     */
    open fun replaceFragment(containerViewId: Int, fragment: android.support.v4.app.Fragment) {
        val fragmentTransaction = supportFragmentManager.beginTransaction()
        fragmentTransaction.replace(containerViewId, fragment)
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
        //        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit()
    }

    fun finishAll() {
        for (activity in mArrayList) {
            if (!activity.isFinishing) {
                activity.finish()
            }
        }
    }





    override fun onDestroy() {
        mArrayList.remove(this)
        super.onDestroy()

    }



}